#include<iostream>
#include<map>
using namespace std;
typedef struct student{
	string name;
	string phone;
	string id;
}Stu;
Stu s[1007];
map<string,int>idToStu;
map<string,int>phoneToStu;

int main()
{
	int n,m,i,tail=0;
	string tPhone,tId,tName;
	string op;
	cin>>n>>m;
	for(i=1;i<=n;i++){
		cin>>s[i].phone>>s[i].id>>s[i].name;
		idToStu[ s[i].id ] = i;
		phoneToStu[ s[i].phone ] = i;
	}
	tail=i;
	while(m--){
		cin>>op;
		if(op=="CP"){
			cin>>tId>>tName>>tPhone;
			i = idToStu[tId];
			if(i==0||s[i].name!=tName)
				cout<<"No Such Person"<<endl;
			else if(phoneToStu[tPhone]){
				cout<<"Phone Already Exists"<<endl;
			}
			else{
				cout<<"CP Success"<<endl;
				phoneToStu[ s[i].phone ] = 0;
				s[i].phone=tPhone;
				phoneToStu[tPhone] = i;
				
			}
		}
		
		else if(op=="CS"){
			cin>>tPhone>>tName>>tId;
			i = phoneToStu[tPhone];
			if(i==0||s[i].name!=tName){
				
				cout<<"No Such Person"<<endl;
			}
			else if(idToStu[tId]){
				cout<<"Sid Already Exists"<<endl;
			}
			else{
				cout<<"CS Success"<<endl;
				idToStu[ s[i].id ] = 0;
				s[i].id=tId;
				idToStu[tId] = i;
			}
		}
		
		else if(op=="NE"){
			cin>>tPhone>>tId>>tName;
			if(phoneToStu[tPhone]||idToStu[tId]){
				cout<<"Already Exists"<<endl;
			}
			else{
				cout<<"Add Success"<<endl;
				i = tail++;
				s[i].name=tName;
				s[i].id=tId;
				s[i].phone=tPhone;
				phoneToStu[tPhone] = i;
				idToStu[tId] = i;
			}
		}
		
		else if(op=="QP"){
			cin>>tPhone;
			i = phoneToStu[tPhone];
			if(i){
				cout<<s[i].id<<" "<<s[i].name<<endl;
			}
			else
				cout<<"No Such Phone"<<endl;
		}
		else if(op=="QS"){
			cin>>tId;
			i = idToStu[tId];
			if(i){
				cout<<s[i].phone<<" "<<s[i].name<<endl;
			}
			else
				cout<<"No Such Sid"<<endl;
		}
		
		else if(op=="CN"){
			cin>>tPhone>>tId>>tName;
			int i1,i2;
			i1 = phoneToStu[tPhone];
			i2 = idToStu[tId];
			if(i1==i2&&i1!=0){
				cout<<"CN Success"<<endl;
				i=i1;
				s[i].name=tName;
			}
			else
				cout<<"No Such Person"<<endl;
		}
		
		else if(op=="DE"){
			cin>>tPhone>>tId;
			int i1,i2;
			i1 = phoneToStu[tPhone];
			i2 = idToStu[tId];
			if(i1==i2&&i1!=0){
				cout<<"Del Success"<<endl;
				i=i1;
				phoneToStu[tPhone] = 0;
				idToStu[tId] = 0;
			}
			else
				cout<<"No Such Person"<<endl;
		}
	}
}
